module multibits_gen_onehot #(
parameter WIDTH=16
)(
input   [WIDTH-1:0] din         ,
output  [WIDTH-1:0] dout_onehot 
);

wire [WIDTH-1:0]mask_high   ;
wire [WIDTH-1:0]inter_onehot;
genvar i;
// 
generate
for(i = 0; i< WIDTH; i = i +1)begin:HIGH
  if( i== 0 )begin
    assign mask_high[i]     = din[i];
    assign inter_onehot[i]  = mask_high[i];
  end
  else begin
    assign mask_high[i]     = din[i] | mask_high[i-1];
    assign inter_onehot[i]  = mask_high[i] & (~mask_high[i-1]);
  end
end
endgenerate

assign dout_onehot = inter_onehot;



endmodule

